
#include "CSceneNodeAnimatorCameraRPG.h"
#include "ISceneManager.h"
#include "os.h"
#include "stdio.h"
namespace irr
{
	namespace scene
	{

		CSceneNodeAnimatorCameraRPG::CSceneNodeAnimatorCameraRPG ( ISceneNode* target, irr::core::vector3df position)
			: Camera(0)
		{
#ifdef _DEBUG
			setDebugName("CCameraSceneNodeAnimatorRPG");
#endif
			if(!target)
				os::Printer::log("SceneNodeAnimatorCameraRPG not created because target is null", ELL_WARNING);
			else
			{
				this->Camera = target->getSceneManager()->addCameraSceneNode();
				
				this->TargetPosition = target->getPosition();
				this->CameraPosition = position;
				
				this->Camera->setTarget(this->TargetPosition);
				this->Camera->setPosition(TargetPosition + CameraPosition);
			}

		}

		CSceneNodeAnimatorCameraRPG::~CSceneNodeAnimatorCameraRPG()
		{
		}
	
		//! OnAnimate() is called just before rendering the whole scene.
		void CSceneNodeAnimatorCameraRPG::animateNode(ISceneNode *node, u32 timeMs)
		{
			if (!node || node->getPosition() == this->TargetPosition)
				return;

			//update camera
			this->TargetPosition = node->getPosition();
			
			this->Camera->setTarget(this->TargetPosition);
			this->Camera->setPosition(TargetPosition + CameraPosition);
		}

	} // namespace scene
} // namespace irr

